home *** CD-ROM | disk | FTP | other *** search
/ IRIX Base Documentation 2001 May / SGI IRIX Base Documentation 2001 May.iso / usr / share / catman / p_man / cat3 / librw / RWVirtualPageHeap.z / RWVirtualPageHeap
Encoding:
Text File  |  1998-10-30  |  7.7 KB  |  199 lines

  1.  
  2.  
  3.  
  4. RRRRWWWWVVVViiiirrrrttttuuuuaaaallllPPPPaaaaggggeeeeHHHHeeeeaaaapppp((((3333CCCC++++++++))))                                RRRRWWWWVVVViiiirrrrttttuuuuaaaallllPPPPaaaaggggeeeeHHHHeeeeaaaapppp((((3333CCCC++++++++))))
  5.  
  6.  
  7.  
  8. NNNNaaaammmmeeee
  9.      RWVirtualPageHeap - Rogue Wave library class
  10.  
  11. SSSSyyyynnnnooooppppssssiiiissss
  12.               #include <rw/vpage.h>
  13.  
  14.  
  15.  
  16.               ((((AAAAbbbbssssttttrrrraaaacccctttt bbbbaaaasssseeee ccccllllaaaassssssss))))
  17.  
  18.  
  19.  
  20.  
  21. DDDDeeeessssccccrrrriiiippppttttiiiioooonnnn
  22.      This is an abstract base class representing an abstract page heap of
  23.      fixed sized pages.  The following describes the model by which
  24.      specializing classes of this class are expected to work.  You allocate a
  25.      page off the abstract heap by calling member function aaaallllllllooooccccaaaatttteeee(((()))) which
  26.      will return a memory "handle," an object of type RRRRWWWWHHHHaaaannnnddddlllleeee.  This handle
  27.      logically represents the page. In order to use the page it must first be
  28.      "locked" by calling member function lllloooocccckkkk(((()))) with the handle as an
  29.      argument.  It is the job of the specializing class of RRRRWWWWVVVViiiirrrrttttuuuuaaaallllPPPPaaaaggggeeeeHHHHeeeeaaaapppp
  30.      to make whatever arrangements are necessary to swap in the page
  31.      associated with the handle and bring it into physical memory.  The actual
  32.      swapping medium could be disk, expanded or extended memory, or a machine
  33.      someplace on a network.  Upon return, lllloooocccckkkk(((()))) returns a pointer to the
  34.      page, now residing in memory.  Once a page is in memory, you are free to
  35.      do anything you want with it although if you change the contents, you
  36.      must call member function ddddiiiirrrrttttyyyy(((()))) before unlocking the page.  Locked
  37.      pages use up memory.  In fact, some specializing classes may have only a
  38.      fixed number of buffers in which to do their swapping.  If you are not
  39.      using the page, you should call uuuunnnnlllloooocccckkkk(((()))).  After calling uuuunnnnlllloooocccckkkk(((()))) the
  40.      original address returned by lllloooocccckkkk(((()))) is no longer valid -- to use the page
  41.      again, it must be locked again with lllloooocccckkkk(((()))).  When you are completely done
  42.      with the page then call ddddeeeeaaaallllllllooooccccaaaatttteeee(((()))) to return it to the abstract heap.
  43.      In practice, managing this locking and unlocking and the inevitable type
  44.      casts can be difficult.  It is usually easier to design a class that can
  45.      work with an abstract heap to bring things in and out of memory
  46.      automatically.  Indeed, this is what has been done with class
  47.      RRRRWWWWTTTTVVVVaaaallllVVVViiiirrrrttttuuuuaaaallllAAAArrrrrrrraaaayyyy<<<<TTTT>>>>, which represents a virtual array of elements of
  48.      type TTTT.  Elements are automatically swapped in as necessary as they are
  49.      addressed.
  50.  
  51. PPPPeeeerrrrssssiiiisssstttteeeennnncccceeee
  52.      None
  53.  
  54. EEEExxxxaaaammmmpppplllleeee
  55.      This example illustrates adding NNNN nodes to a linked list.  In this linked
  56.      list, a "pointer" to the next node is actually a handle.
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.                                                                         PPPPaaaaggggeeee 1111
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. RRRRWWWWVVVViiiirrrrttttuuuuaaaallllPPPPaaaaggggeeeeHHHHeeeeaaaapppp((((3333CCCC++++++++))))                                RRRRWWWWVVVViiiirrrrttttuuuuaaaallllPPPPaaaaggggeeeeHHHHeeeeaaaapppp((((3333CCCC++++++++))))
  71.  
  72.  
  73.  
  74.               #include <rw/vpage.h>
  75.  
  76.  
  77.  
  78.               struct Node {
  79.             int  key;
  80.             RWHandle  next;
  81.           };
  82.           RWHandle head = 0;
  83.           void addNodes(RWVirtualPageHeap& heap, unsigned N) {
  84.             for (unsigned i=0; i<N; i++){
  85.               RWHandle h = heap.allocate();
  86.               Node* newNode = (Node*)heap.lock(h);
  87.               newNode->key  = i;
  88.               newNode->next = head;
  89.               head = h;
  90.               heap.dirty(h);
  91.               heap.unlock(h);
  92.             }
  93.           }
  94.  
  95.  
  96. PPPPuuuubbbblllliiiicccc CCCCoooonnnnssssttttrrrruuuuccccttttoooorrrr
  97.               RWVirtualPageHeap(unsigned pgsize);
  98.  
  99.  
  100.      Sets the size of a page.
  101.  
  102.  
  103.  
  104.  
  105.  
  106. PPPPuuuubbbblllliiiicccc DDDDeeeessssttttrrrruuuuccccttttoooorrrr
  107.               virtual ~RWVirtualPageHeap();
  108.  
  109.  
  110.      The destructor has been made virtual to give specializing classes a
  111.      chance to deallocate any resources that they may have allocated.
  112.  
  113. PPPPuuuubbbblllliiiicccc MMMMeeeemmmmbbbbeeeerrrr FFFFuuuunnnnccccttttiiiioooonnnnssss
  114.               unsigned
  115.           ppppaaaaggggeeeeSSSSiiiizzzzeeee() const;
  116.  
  117.  
  118.      Returns the page size for this abstract page heap.
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.                                                                         PPPPaaaaggggeeee 2222
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136. RRRRWWWWVVVViiiirrrrttttuuuuaaaallllPPPPaaaaggggeeeeHHHHeeeeaaaapppp((((3333CCCC++++++++))))                                RRRRWWWWVVVViiiirrrrttttuuuuaaaallllPPPPaaaaggggeeeeHHHHeeeeaaaapppp((((3333CCCC++++++++))))
  137.  
  138.  
  139.  
  140. PPPPuuuubbbblllliiiicccc PPPPuuuurrrreeee VVVViiiirrrrttttuuuuaaaallll FFFFuuuunnnnccccttttiiiioooonnnnssss
  141.               virtual RWHandle
  142.           aaaallllllllooooccccaaaatttteeee() = 0
  143.  
  144.  
  145.      Allocates a page off the abstract heap and returns a handle for it.  If
  146.      the specializing class is unable to honor the request, then it should
  147.      return a zero handle.
  148.  
  149.               virtual void
  150.           ddddeeeeaaaallllllllooooccccaaaatttteeee(RWHandle h) = 0;
  151.  
  152.  
  153.      Deallocate the page associated with handle hhhh.  It is not an error to
  154.      deallocate a zero handle.
  155.  
  156.               virtual void
  157.           ddddiiiirrrrttttyyyy(RWHandle h) = 0;
  158.  
  159.  
  160.      Declare the page associated with handle hhhh to be "dirty."  That is, it has
  161.      changed since it was last locked.  The page must be locked before calling
  162.      this function.
  163.  
  164.               virtual void*
  165.           lllloooocccckkkk(RWHandle h) = 0;
  166.  
  167.  
  168.      Lock the page, swapping it into physical memory, and return an address
  169.      for it.  A nnnniiiillll pointer will be returned if the specializing class is
  170.      unable to honor the lock.  The returned pointer should be regarded as
  171.      pointing to a buffer of the page size.
  172.  
  173.               virtual void
  174.           uuuunnnnlllloooocccckkkk(RWHandle h) = 0;
  175.  
  176.  
  177.      Unlock a page.  A page must be locked before calling this function.
  178.      After calling this function the address returned by lllloooocccckkkk(((()))) is no longer
  179.      valid.
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.                                                                         PPPPaaaaggggeeee 3333
  196.  
  197.  
  198.  
  199.